import 'package:flutter/material.dart';
import 'package:schoollifedemo/base/common_function.dart';
import 'package:schoollifedemo/commonwidget/common_base_widget.dart';

class ButtonWidget extends BaseStatefulWidget {
  final OnButtonClick? onButtonClick;
  double width;
  double height;

  double paddingLeft;
  double paddingTop;
  double paddingRight;
  double paddingBottom;

  double radius;

  Color disableColor;
  Color enableColor;

  Widget insideWidget;

  ButtonWidget({
    Key? key,
    this.onButtonClick,
    this.width = 100,
    this.height = 50,
    this.paddingLeft = 10,
    this.paddingBottom = 5,
    this.paddingTop = 5,
    this.paddingRight = 10,
    this.disableColor = const Color(0x80529FE8),
    this.enableColor = const Color(0xFF529FE8),
    this.radius = 10,
    this.insideWidget = const SizedBox(),
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _ButtonWidgetState();
  }
}

class _ButtonWidgetState extends BaseWidgetState<ButtonWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        top: widget.paddingTop,
        left: widget.paddingLeft,
        right: widget.paddingRight,
        bottom: widget.paddingBottom,
      ),
      width: widget.width,
      height: widget.height,
      child: ElevatedButton(
        style: ButtonStyle(
          shape: MaterialStateProperty.all(
            RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(widget.radius),
            ),
          ),
          backgroundColor: MaterialStateProperty.resolveWith<Color>(
            (Set<MaterialState> states) {
              if (states.contains(MaterialState.pressed)) {
                return Theme.of(context).colorScheme.primary.withOpacity(0.5);
              } else if (states.contains(MaterialState.disabled)) {
                return widget.disableColor;
              }
              return widget.enableColor; // Use the component's default.
            },
          ),
        ),
        onPressed: widget.onButtonClick,
        child: widget.insideWidget,
      ),
    );
  }
}
